<template>
  <div class="editable-cell">
    <div v-if="editable" class="editable-cell-input-wrapper">
      <a-select :default-value="selected" v-model="selected" style="width: 100px">
        <a-select-option v-for="(status, index) in select" :key="index">
          {{status}}
        </a-select-option>
      </a-select>
      <a-icon type="check" v-action:edit-status class="editable-cell-icon-check" @click="check" />
    </div>
    <div v-else class="editable-cell-text-wrapper">
      {{ selectedText || ' ' }}
      <a-icon type="edit" v-action:edit-status class="editable-cell-icon" @click="edit" />
    </div>
  </div>
</template>

<script>
export default {
  name: 'EditableStatus',
  props: {
    status: {
      type: Number,
    },
  },
  data() {
    return {
      editable: false,
      select: ['空闲', '已预约'],
      selected: 0,
    }
  },
  computed: {
    selectedText() {
      return this.select[this.selected]
    }
  },
  created() {
    this.selected = this.status
  },
  methods: {
    // 确认按钮
    check() {
      this.editable = false
      this.$emit('change', this.selected)
    },
    // 切换状态
    edit() {
      this.editable = true
    },
  },
}
</script>

<style lang="less" scoped>
.editable-cell {
  .editable-cell-input-wrapper {
    .editable-cell-icon-check {
      margin-left: 4px;
      &:hover {
        color: #108ee9;
      }
    }
  }

  .editable-cell-text-wrapper {
    .editable-cell-icon {
      margin-left: 4px;
      &:hover {
        color: #108ee9;
      }
    }
  }
}
</style>